package org.colcon.web.client.ui.deprecated;

import java.util.List;

import org.colcon.web.client.Collective_Congress;
import org.colcon.web.client.ui.ClickablePanel;
import org.colcon.web.model.User;
import org.colcon.web.model.framework.IItem;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HTML;

public class UsersLink extends ClickablePanel
{
	public UsersLink(Collective_Congress client)
	{
		super(client, "header-item", "users");
	}
	
	public void click()
	{
		getBodyPanel().clear();
		getBodyPanel().add(new HTML("Loading..."));
		
		getService().getUsers(new AsyncCallback<List<User>>()
		{
			public void onFailure(Throwable caught)
			{
				getBodyPanel().clear();
				caught.printStackTrace();
				getBodyPanel().add(new HTML(caught.getMessage()));
			}
			
			public void onSuccess(List<User> users)
			{
				getBodyPanel().clear();
				getBodyPanel().add(new NamedItemListPanel(getClient(), users.toArray(new IItem[0])));
			}
		});
	}
}